<template>
  <div class="hello">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
    >
      <el-menu-item index="home">主页</el-menu-item>
      <el-menu-item index="menu">菜单 </el-menu-item>
      <el-menu-item index="admin">管理</el-menu-item>
      <el-menu-item index="about">关于我们</el-menu-item>
      <el-menu-item index="5">登录</el-menu-item>
      <el-menu-item index="6">注册</el-menu-item>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {

    };
  },
  computed: {
    activeIndex() {
      //this.$route是当前页面的路由信息
      // console.log(this.$route)
      return this.$route.name;
    },
  },
  methods: {
    handleSelect(key, keyPath) {
      //手动路由
      // console.log(key, keyPath);
      // this.$router.replace(key)
      this.$router.push({name:key})
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
